package com.monkeygroup.mygoplus.ecchat.ui.contact.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.monkeygroup.mygoplus.R;
import com.monkeygroup.mygoplus.common.DefinedView.CircleImageView;
import com.monkeygroup.mygoplus.ecchat.ui.contact.entity.ContactMemberDTO;

import java.util.List;

/**
 * Created by Administrator on 2017/6/21.
 */
public class MemberListAdapter extends BaseAdapter {
    private List<ContactMemberDTO> data = null;
    private Context mContext;
    private LayoutInflater inflater;

    public MemberListAdapter(Context context, List<ContactMemberDTO> data) {
        this.mContext = context;
        this.data = data;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        if (data != null) {
            return data.size();
        }

        return 0;
    }

    @Override
    public ContactMemberDTO getItem(int position) {
        if (data != null && data.size() > 0) {
            return data.get(position);
        }

        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_contact_member, null);
            holder.layout_item = (LinearLayout) convertView.findViewById(R.id.layout_item);
            holder.layout_more = (LinearLayout) convertView.findViewById(R.id.layout_more);
            holder.member_name = (TextView) convertView.findViewById(R.id.member_name);
            holder.member_head = (CircleImageView) convertView.findViewById(R.id.member_head);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.layout_item.setVisibility(View.VISIBLE);
        holder.layout_more.setVisibility(View.GONE);
        ContactMemberDTO memberDTO = getItem(position);
        holder.member_name.setText(memberDTO.getName());

        return convertView;
    }

    private class ViewHolder {
        LinearLayout layout_item;
        LinearLayout layout_more;
        CircleImageView member_head;
        TextView member_name;
    }
}